package com.txy.springcloud.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.beans.PropertyVetoException;

@Configuration
public class Config {


    @Bean
    public ComboPooledDataSource dataSource(
            @Value("${mysql.jdbc.driver}") String driver,
            @Value("${mysql.jdbc.url}") String url,
            @Value("${mysql.jdbc.username}") String username,
            @Value("${mysql.jdbc.password}") String password
            ) throws PropertyVetoException {
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setDriverClass(driver);
        dataSource.setJdbcUrl(url);
        dataSource.setUser(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
